package com.oig.sys.msg.service.impl;

import com.oig.common.constants.CommonEnum;
import com.oig.sys.msg.dao.ITbMqMsgHisDao;
import com.oig.sys.msg.entity.TbMqMsg;
import com.oig.sys.msg.entity.TbMqMsgHis;
import com.oig.sys.msg.service.ITbMqMsgHisService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Slf4j
@RequiredArgsConstructor
public class TbMqMsgHisServiceImpl implements ITbMqMsgHisService {

    private final ITbMqMsgHisDao tbMqMsgHisDao;

    @Transactional
    @Override
    public void addMqMsgHis(TbMqMsg mqMsg) {
        TbMqMsgHis mqMsgHis = new TbMqMsgHis();
        BeanUtils.copyProperties(mqMsg, mqMsgHis, "id");
        mqMsgHis.setMqId(mqMsg.getId());
        mqMsgHis.setSendFlag(CommonEnum.FlagEnum.TRUE_FLAG.getCode());
        mqMsgHis.setSendNum(mqMsg.getSendNum()==null?1:mqMsg.getSendNum()+1);
        mqMsgHis.setSendTime(new Date());
        this.tbMqMsgHisDao.save(mqMsgHis);
    }
}
